package top.azusall.securitydemo.handle;

import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authorization.AuthorizationDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.azusall.common.entity.R;

/**
 * @author houmo
 */
@RestControllerAdvice
public class ExceptionAdvice {


    @ExceptionHandler(BadCredentialsException.class)
    public R handleBadCredentialsException(BadCredentialsException e) {
        return R.err(e.getMessage(), null);
    }

    @ExceptionHandler(AuthorizationDeniedException.class)
    public R handleAuthorizationDeniedException(AuthorizationDeniedException e) {
        return new R(401, "权限不足", null);
    }



}
